Page({
  data: {},
  onLoad: function (e) {
    getApp().page.onLoad(this, e);
  
    var t = getApp().getUser();
    console.log(t);
    this.setData({
      
      user_info: t
    });
    var o = "";
  
    if ("undefined" == typeof my) o = decodeURIComponent(e.scene); else if (null !== getApp().query) {
      console.log(12312312, getApp().query)
      var n = getApp().query;
      console.log(n,99999)
      getApp().query = null, o = n.id;
    }
   var a= this;
    getApp().request({
          url: getApp().api.order.user_clerk,
          data: {
            id: o,
            userid:t.id
          },
          success: function (e) {
           if(e.code==0)
           {
             getApp().core.showModal({
               title: "提示",
               content: '您不是核销员，不能核销',
               showCancel: !1,
               success: function (e) {

               }
             });
           }else{
             a.setData({
               coupondata:e.data
             })
           }
          
          },
          complete: function () {
            getApp().core.hideLoading();
          }
        })
  },
  onShow: function () {
    getApp().page.onShow(this);
  },
  remarks(e){
    
    var remarks = e.detail.value;
    this.setData({
      remarks: remarks
    })
  },
  confirm:function(e)
  {

    var that = this;
    var t = getApp().getUser();
    var bid = that.data.coupondata.bid;
    var remarks = that.data.remarks;
    var uid = that.data.coupondata.user_id;
    console.log(remarks, bid,88899)
    getApp().request({
      url: getApp().api.order.user_clerkcoupon,
      data: {
        bid: bid,
        remarks: remarks,
        uid:uid,
        clerkuid:t.id,
      },
      success: function (e) {
        console.log(e,22222);
        if (e.code == 3) {
          getApp().core.showModal({
            title: "提示",
            content: '已过期不能核销',
            showCancel: !1,
            success: function (e) {
              e.confirm && getApp().core.redirectTo({
                url: "/pages/user-coupon/user-coupon"
              });

            }
          });
        } 
        if (e.code == 0) {
          getApp().core.showModal({
            title: "提示",
            content: '核销成功',
            showCancel: !1,
            success: function (e) {
              e.confirm &&getApp().core.redirectTo({
                url: "/pages/user-coupon/user-coupon"
              });

            }
          });
        } 
        if(e.code==2){
          getApp().core.showModal({
            title: "提示",
            content: '核销次数不够',
            showCancel: !1,
            success: function (e) {
              e.confirm &&getApp().core.redirectTo({
                url: "/pages/user-coupon/user-coupon"
              });

            }
          });
        }

      },
      complete: function () {
        getApp().core.hideLoading();
      }
    })
  }
});